<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6"
                :xs="24">
          <user-card :user="user" />
        </el-col>

        <el-col :span="18"
                :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane :label="$t('profile.account')"
                           name="username">
                <Account :user="user" />
              </el-tab-pane>
              <!-- <span v-permission="['admin']"> -->
              <el-tab-pane :label="$t('profile.userManagement')"
                           name="userTable"
                           v-if="user.role=='admin'">
                <user-table />
              </el-tab-pane>
              <!-- </span> -->
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/UserCard'
import Account from './components/Account'
import UserTable from './components/UserTable'
import permission from '@/directive/permission/index.js' // 权限判断指令

export default {
  name: 'Profile',
  // components: { UserCard, Activity, Timeline, Username, UserTable },
  components: { UserCard, Account, UserTable },
  directives: { permission },

  data() {
    return {
      user: {},
      activeTab: 'username'
    }
  },
  computed: {
    ...mapGetters(['name', 'avatar', 'roles'])
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      this.user = {
        name: this.name,
        role: this.roles.join(' | '),
        email: 'admin@test.com',
        avatar: this.avatar
      }
      console.log(this.user.role)
    }
  }
}
</script>
